home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Mozetta™ / Source / mozilla⁄network⁄main / mkgeturl.c
Encoding:
Text File  |  1998-06-21  |  4.5 KB  |  166 lines  |  [TEXT/CWIE]

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*
  19.  * mkgeturl.c
  20.  *  This file implements the main calling api for netlib.
  21.  *    Includes NET_InitNetlib, NET_Shutdown, NET_GetURL, and NET_ProcessNet
  22.  *
  23.  * Designed and originally implemented by Lou Montulli '94
  24.  * Additions/Changes by Judson Valeski, Gagan Saksena 1997.
  25.  */
  26.  
  27.  
  28.  
  29. Note:  Insert our code (which begins after the dashed line)
  30.        after the following in the NET_GetURL() routine:
  31.  
  32.  
  33.     /* the FE's were screwing up the use of force_reload
  34.      * to get around a bug in the scroll to named anchor
  35.      * code.  So I gave them an enum NET_RESIZE_RELOAD
  36.      * that they could use instead.  NET_RESIZE_RELOAD
  37.      * should be treated just like NET_DONT_RELOAD within
  38.      * the netlib
  39.      */
  40.     if((URL_s->force_reload == NET_RESIZE_RELOAD) ||
  41.        (URL_s->force_reload == NET_CACHE_ONLY_RELOAD))
  42.         URL_s->force_reload = NET_DONT_RELOAD;
  43.  
  44.  
  45. ---------------
  46.  
  47.  
  48.     /* rjc / shapiro hack begins here */
  49.  
  50. #define    ENABLE_BABEL        1
  51.  
  52. #define    BABEL_URL        "http://babelfish.altavista.digital.com/cgi-bin/translate?"
  53. #define    PIGLATIN_URL        "http://voyager.cns.ohiou.edu/~jrantane/cgi/pig.cgi?text=%s&SUBMIT=CONVERT"
  54. #define    BACKWARDS_URL        "http://smeg.com/backwards/b2.cgi?url=%s"
  55.  
  56. #define    BABEL_NO_LANGUAGE    1
  57. #define    BABEL_RANDOM_LANGUAGE    3
  58. #define    PIGLATIN_LANGUAGE    4
  59. #define    BACKWARDS_LANGUAGE    5
  60. #define    BABEL_FIRST_ITEM    7
  61.  
  62. #ifdef    ENABLE_BABEL
  63.  
  64.     /* need to set: "doit" = "done", "urltext" = URL, and
  65.         "lp" = one of the following:
  66.         "en_fr" : English to French
  67.         "en_de" : English to German
  68.         "en_it" : English to Italian
  69.         "en_pt" : English to Portuguese
  70.         "en_es" : English to Spanish
  71.         "fr_en" : French to English
  72.         "de_en" : German to English
  73.         "it_en" : Italian to English
  74.         "es_en" : Spanish to English
  75.         "pt_en" : Portuguese to English
  76.     */
  77.  
  78.     if ((URL_s->method == URL_GET_METHOD) && (CLEAR_CACHE_BIT(output_format) == FO_PRESENT) && 
  79.         ((type == HTTP_TYPE_URL) || (type == SECURE_HTTP_TYPE_URL)) )
  80.     {
  81.         int32        hackLanguage;
  82.         char        *munged, *postData, *escaped;
  83.         char        *babelMappings [] =
  84.                 {
  85.                     "en_fr", "en_de", "en_it", "en_pt", "en_es",
  86.                     "fr_en", "de_en", "it_en", "es_en", "pt_en",
  87.                     NULL
  88.                 };
  89.  
  90.         PREF_GetIntPref("hack.language", &hackLanguage);
  91.         if (hackLanguage > BABEL_NO_LANGUAGE)
  92.         {
  93.             escaped = NET_Escape(URL_s->address, URL_XPALPHAS);
  94.  
  95.             if (hackLanguage == BABEL_RANDOM_LANGUAGE)
  96.             {
  97.                 hackLanguage = BABEL_FIRST_ITEM + Random() % 10;
  98.             }
  99.             if (hackLanguage == PIGLATIN_LANGUAGE)
  100.             {
  101.                 if ((munged = PR_smprintf(PIGLATIN_URL, escaped)) != NULL)
  102.                 {
  103.                     if (URL_s->address != NULL)
  104.                     {
  105.                         PR_Free(URL_s->address);
  106.                     }
  107.                     URL_s->address = munged;
  108.                 }
  109.             }
  110.             else if (hackLanguage == BACKWARDS_LANGUAGE)
  111.             {
  112.                 if ((munged = PR_smprintf(BACKWARDS_URL, escaped)) != NULL)
  113.                 {
  114.                     if (URL_s->address != NULL)
  115.                     {
  116.                         PR_Free(URL_s->address);
  117.                     }
  118.                     URL_s->address = munged;
  119.                 }
  120.             }
  121.             else
  122.             {
  123.                 munged = (char*) PR_Malloc(PL_strlen(BABEL_URL) + 1);
  124.  
  125.                 if ((postData = PR_smprintf("doit=done&urltext=%s&lp=%s",
  126.                     ((escaped != NULL) ? escaped : URL_s->address),
  127.                     babelMappings[hackLanguage - BABEL_FIRST_ITEM])) != NULL)
  128.                 {
  129.                     /* mangle URL to point to babelfish */
  130.                     PL_strcpy(munged, BABEL_URL);
  131.                     if (URL_s->address != NULL)
  132.                     {
  133.                         PR_Free(URL_s->address);
  134.                     }
  135.                     URL_s->address = munged;
  136.  
  137.                     /* babelfish wants a HTTP POST */
  138.                     URL_s->method = URL_POST_METHOD;
  139.  
  140.                     /* set POST information for babelfish */
  141.  
  142.                     if (URL_s->post_data != NULL)
  143.                     {
  144.                         PR_Free(URL_s->post_data);
  145.                     }
  146.                     URL_s->post_data = postData;
  147.                     URL_s->post_data_size = strlen(postData);
  148.                     URL_s->post_headers = PR_smprintf("Content-type: application/x-www-form-urlencoded\r\nContent-length: %lu\r\n",
  149.                         strlen(postData));
  150.                 }
  151.                 else
  152.                 {
  153.                     PR_Free(munged);
  154.                 }
  155.             }
  156.             if (escaped != NULL)
  157.             {
  158.                 FREE(escaped);
  159.             }
  160.         }
  161.     }
  162.  
  163.     /* rjc / shapiro hack ends here */
  164. #endif
  165.  
  166.